package com.ssy.lingxi.marketing.controller.activity;

import com.ssy.lingxi.common.constant.marketing.ActivityTypeEnum;
import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.model.dto.UserLoginCacheDTO;
import com.ssy.lingxi.common.model.vo.SelectItemVO;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.marketing.model.constant.MerchantActivityInnerStatusEnum;
import com.ssy.lingxi.marketing.model.vo.activity.request.*;
import com.ssy.lingxi.marketing.model.vo.activity.response.*;
import com.ssy.lingxi.marketing.model.vo.common.request.CommonIdReq;
import com.ssy.lingxi.marketing.model.vo.common.response.PageItemVO;
import com.ssy.lingxi.marketing.model.vo.coupon.request.ActivityMerchantPrizeCouponRequest;
import com.ssy.lingxi.marketing.model.vo.coupon.request.ActivityMerchantSubsidiaryCouponRequest;
import com.ssy.lingxi.marketing.model.vo.coupon.request.FilterSkuIdRequest;
import com.ssy.lingxi.marketing.model.vo.coupon.request.FilterSkuIdResponse;
import com.ssy.lingxi.marketing.model.vo.coupon.response.ActivityGoodsCouponResponse;
import com.ssy.lingxi.marketing.model.vo.coupon.response.ActivityPrizeCouponResponse;
import com.ssy.lingxi.marketing.service.ICommonService;
import com.ssy.lingxi.marketing.service.IMerchantActivityService;
import com.ssy.lingxi.marketing.service.IMerchantCouponService;
import com.ssy.lingxi.marketing.serviceimpl.base.activity.BaseActivityRecordService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.Collections;
import java.util.List;

/**
 * @menu 营销能力 - 商家营销活动管理
 * @author yzc
 * @version 2.0.0
 * @date 2021/8/24
 */
@RestController
@RequestMapping("/marketing/merchant/activity")
public class MerchantActivityController extends BaseController {

    @Resource
    private IMerchantActivityService merchantActivityService;
    @Resource
    private ICommonService commonService;
    @Resource
    private BaseActivityRecordService activityRecordService;
    @Resource
    private IMerchantCouponService merchantCouponService;

    /**
     * 商家营销活动查询 - 外部状态列表
     */
/*22.1.20版废弃    @RequestMapping(value = "/getOuterStatusList", method = RequestMethod.GET)
    public Wrapper<List<PageItemVO>> getOuterStatusList() {
        return commonService.getStatusList(MerchantActivityOuterStatusEnum.class);
    }*/

    /**
     * 商家营销活动查询 - 内部状态列表
     */
    @RequestMapping(value = "/getInnerStatusList", method = RequestMethod.GET)
    public Wrapper<List<PageItemVO>> getStatusList() {
        return commonService.getStatusList(MerchantActivityInnerStatusEnum.class);
    }

    /**
     * 商家营销活动查询 - 活动类型列表
     */
    @RequestMapping(value = "/getActivityTypeList", method = RequestMethod.GET)
    public Wrapper<List<PageItemVO>> getActivityTypeList() {
        return commonService.getStatusList(ActivityTypeEnum.class);
    }

    /**
     * 商家营销活动查询 - 分页列表
     */
    @RequestMapping(value = "/page", method = RequestMethod.GET)
    public Wrapper<PageData<MerchantActivitySummaryPageResp>> pageSummary(@Valid MerchantActivityCommonPageVO pageReq) {
        UserLoginCacheDTO loginUser = getSysUser();
        return merchantActivityService.pageSummary(loginUser, pageReq);
    }

    /**
     * 商家营销活动查询 - 活动详情
     */
    @GetMapping(value = "/detail")
    public Wrapper<MerchantActivityDetailResp> detail(CommonIdReq req) {
        UserLoginCacheDTO loginUser = getSysUser();
        return merchantActivityService.detail(loginUser, req);
    }

    /**
     * 商家营销活动查询 - 活动详情 - 活动商品(分页)
     */
    @RequestMapping(value = "/detail/goods/page", method = RequestMethod.GET)
    public Wrapper<PageData<McActivityGoodsPageResp>> pageByActivityGoods(@Valid PfActivityGoodsPageReq req) {
        UserLoginCacheDTO loginUser = getSysUser();
        return merchantActivityService.pageByActivityGoods(loginUser, req);
    }

    /**
     * 商家营销活动查询 - 活动详情 - 活动商品 - 选择附属优惠券查询条件
     * @return 返回结果
     */
    @RequestMapping(value = "/detail/goods/coupon/select/condition", method = RequestMethod.GET)
    public Wrapper<List<SelectItemVO>> selectSubsidiaryCouponCondition() {
        return merchantCouponService.selectSubsidiaryCouponCondition();
    }

    /**
     * 商家营销活动查询 - 活动详情 - 活动商品 - 选择附属优惠券
     **/
    @RequestMapping(value = "/detail/goods/coupon/select", method = RequestMethod.GET)
    public Wrapper<PageData<ActivityGoodsCouponResponse>> selectSubsidiaryCouponList(HttpServletRequest httpRequest, ActivityMerchantSubsidiaryCouponRequest request) {
        return merchantCouponService.selectSubsidiaryCouponList(request, getSysUser(httpRequest));
    }

    /**
     * 商家营销活动查询 - 活动详情 - 奖品 - 选择0元购买抵扣券
     **/
    @RequestMapping(value = "/detail/prize/coupon/select", method = RequestMethod.GET)
    public Wrapper<PageData<ActivityPrizeCouponResponse>> selectPrizeCouponList(HttpServletRequest httpRequest, ActivityMerchantPrizeCouponRequest request) {
        return merchantCouponService.selectPrizeCouponList(request, getSysUser(httpRequest));
    }

    /**
     * 商家营销活动查询 - 活动详情 - 外部流转记录(分页)
     */
/*22.1.20版废弃    @RequestMapping(value = "/outer/record/page", method = RequestMethod.GET)
    public Wrapper<PageData<ActivityOuterRecordResp>> pageOuterRecordList(@Valid ActivityOuterRecordPageReq pageReq) {
        UserLoginCacheDTO loginUser = getSysUser();
        return activityRecordService.pageMerchantActivityOuterRecord(loginUser, pageReq);
    }*/

    /**
     * 商家营销活动查询 - 活动详情 - 内部流转记录(分页)
     */
    @RequestMapping(value = "/inner/record/page", method = RequestMethod.GET)
    public Wrapper<PageData<ActivityInnerRecordResp>> pageInnerRecordList(@Valid ActivityInnerRecordPageReq pageReq) {
        UserLoginCacheDTO loginUser = getSysUser();
        return activityRecordService.pageMerchantActivityInnerRecord(loginUser, pageReq);
    }

    /**
     * 商家营销活动查询 - 终止
     */
    @RequestMapping(value = "/stop", method = RequestMethod.POST)
    public Wrapper<Void> stop(@RequestBody @Valid ActivityActionReq stopReq) {
        UserLoginCacheDTO loginUser = getSysUser();
        return merchantActivityService.stop(loginUser, stopReq);
    }

    /**
     * 商家营销活动查询 - 重新启动
     */
    @RequestMapping(value = "/restart", method = RequestMethod.POST)
    public Wrapper<Void> restart(@RequestBody @Valid ActivityActionReq restartReq) {
        UserLoginCacheDTO loginUser = getSysUser();
        return merchantActivityService.restart(loginUser, restartReq);
    }

    /**
     * 待提交审核商家营销活动 - 分页列表
     */
    @RequestMapping(value = "/page/tobe/submit/exam", method = RequestMethod.GET)
    public Wrapper<PageData<MerchantActivitySubmitExamPageResp>> pageByToBeSubmitExam(@Valid MerchantActivityCommonPageVO pageReq) {
        UserLoginCacheDTO loginUser = getSysUser();
        return merchantActivityService.pageByToBeSubmitExam(loginUser, pageReq);
    }

    /**
     * 待新增商家营销活动 - 新增
     */
    @PostMapping(value = "/save")
    public Wrapper<Void> save(@RequestBody @Valid MerchantActivityAddReq req) {
        UserLoginCacheDTO loginUser = getSysUser();
        return merchantActivityService.saveMerchantActivity(loginUser, req);
    }

    /**
     * 待新增商家营销活动 - 修改
     */
    @PostMapping(value = "/update")
    public Wrapper<Void> update(@RequestBody @Valid MerchantActivityUpdateReq req) {
        UserLoginCacheDTO loginUser = getSysUser();
        return merchantActivityService.updateMerchantActivity(loginUser, req);
    }

    /**
     * 待新增商家营销活动 - 查询活动商品过滤的skuId
     */
    @PostMapping(value = "/getFilterSkuId")
    public Wrapper<FilterSkuIdResponse> getFilterSkuId(@RequestBody @Valid FilterSkuIdRequest req) {
        UserLoginCacheDTO loginUser = getSysUser();
        return merchantActivityService.getFilterSkuId(loginUser, req);
    }

    /**
     * 待新增商家营销活动 - 提交审核
     */
    @PostMapping(value = "/submit/examine")
    public Wrapper<Void> submitExamine(@Valid @RequestBody ActivitySubmitReq req) {
        UserLoginCacheDTO loginUser = getSysUser();
        return merchantActivityService.submitExamine(loginUser, Collections.singletonList(req.getId()));
    }

    /**
     * 待新增商家营销活动 - 批量提交审核
     */
    @PostMapping(value = "/submit/examine/batch")
    public Wrapper<Void> batchSubmitExamine(@Valid @RequestBody CommonIdsReq req) {
        UserLoginCacheDTO loginUser = getSysUser();
        return merchantActivityService.submitExamine(loginUser, req.getIds());
    }

    /**
     * 待新增商家营销活动 - 删除
     */
    @PostMapping(value = "/delete")
    public Wrapper<Void> delete(@Valid @RequestBody ActivitySubmitReq req) {
        UserLoginCacheDTO loginUser = getSysUser();
        return merchantActivityService.batchDelete(loginUser, Collections.singletonList(req.getId()));
    }

    /**
     * 待新增商家营销活动 - 批量删除
     */
    @PostMapping(value = "/delete/batch")
    public Wrapper<Void> batchDelete(@Valid @RequestBody CommonIdsReq req) {
        UserLoginCacheDTO loginUser = getSysUser();
        return merchantActivityService.batchDelete(loginUser, req.getIds());
    }

    /**
     * 待审核商家营销活动(一级) - 分页列表
     */
    @RequestMapping(value = "/page/examine/step1", method = RequestMethod.GET)
    public Wrapper<PageData<MerchantActivityExamPageResp>> pageByExamineStep1(@Valid MerchantActivityCommonPageVO pageReq) {
        UserLoginCacheDTO loginUser = getSysUser();
        return merchantActivityService.pageByExamineStep1(loginUser, pageReq);
    }

    /**
     * 待审核商家营销活动(一级) - 审核
     */
    @PostMapping(value = "/examine/step1")
    public Wrapper<Void> examineStep1Update(@RequestBody @Valid ActivityExamineReq req) {
        UserLoginCacheDTO loginUser = getSysUser();
        return merchantActivityService.examineStep1Update(loginUser, req);
    }

    /**
     * 待审核商家营销活动(一级) - 批量审核
     */
    @PostMapping(value = "/examine/step1/batch")
    public Wrapper<Void> batchExamineStep1Update(@RequestBody @Valid CommonIdsReq req) {
        UserLoginCacheDTO loginUser = getSysUser();
        return merchantActivityService.batchExamineStep1Update(loginUser, req);
    }

    /**
     * 待审核商家营销活动(二级) - 分页列表
     */
    @RequestMapping(value = "/page/examine/step2", method = RequestMethod.GET)
    public Wrapper<PageData<MerchantActivityExamPageResp>> pageByExamineStep2(@Valid MerchantActivityCommonPageVO pageReq) {
        UserLoginCacheDTO loginUser = getSysUser();
        return merchantActivityService.pageByExamineStep2(loginUser, pageReq);
    }

    /**
     * 待审核商家营销活动(二级) - 审核
     */
    @PostMapping(value = "/examine/step2")
    public Wrapper<Void> examineStep2Update(@RequestBody @Valid ActivityExamineReq req) {
        UserLoginCacheDTO loginUser = getSysUser();
        return merchantActivityService.examineStep2Update(loginUser, req);
    }

    /**
     * 待审核商家营销活动(二级) - 批量审核
     */
    @PostMapping(value = "/examine/step2/batch")
    public Wrapper<Void> batchExamineStep2Update(@RequestBody @Valid CommonIdsReq req) {
        UserLoginCacheDTO loginUser = getSysUser();
        return merchantActivityService.batchExamineStep2Update(loginUser, req);
    }

    /**
     * 待提交营销活动 - 分页列表
     */
    @RequestMapping(value = "/page/tobe/submit", method = RequestMethod.GET)
    public Wrapper<PageData<MerchantActivitySubmitPageResp>> pageByToBeSubmit(@Valid MerchantActivityCommonPageVO pageReq) {
        UserLoginCacheDTO loginUser = getSysUser();
        return merchantActivityService.pageByToBeSubmit(loginUser, pageReq);
    }

    /**
     * 待提交营销活动 - 提交
     */
    @PostMapping(value = "/submit")
    public Wrapper<Void> submit(@RequestBody @Valid ActivitySubmitReq req) {
        UserLoginCacheDTO loginUser = getSysUser();
        return merchantActivityService.submit(loginUser, Collections.singletonList(req.getId()));
    }

    /**
     * 待提交营销活动 - 批量提交
     */
    @PostMapping(value = "/submit/batch")
    public Wrapper<Void> batchSubmit(@RequestBody @Valid CommonIdsReq req) {
        UserLoginCacheDTO loginUser = getSysUser();
        return merchantActivityService.submit(loginUser, req.getIds());
    }

    /**
     * 待上线商家营销活动 - 分页列表
     */
    @RequestMapping(value = "/page/tobe/online", method = RequestMethod.GET)
    public Wrapper<PageData<MerchantActivityOnlinePageResp>> pageByToBeOnline(@Valid MerchantActivityCommonPageVO pageReq) {
        UserLoginCacheDTO loginUser = getSysUser();
        return merchantActivityService.pageByToBeOnline(loginUser, pageReq);
    }

    /**
     * 待上线商家营销活动 - 上线活动
     */
    @PostMapping(value = "/online")
    public Wrapper<Void> online(@RequestBody @Valid ActivitySubmitReq req) {
        UserLoginCacheDTO loginUser = getSysUser();
        return merchantActivityService.onlineUpdate(loginUser, Collections.singletonList(req.getId()));
    }

    /**
     * 待上线商家营销活动 - 批量上线活动
     */
    @PostMapping(value = "/online/batch")
    public Wrapper<Void> batchOnline(@RequestBody @Valid CommonIdsReq req) {
        UserLoginCacheDTO loginUser = getSysUser();
        return merchantActivityService.onlineUpdate(loginUser, req.getIds());
    }
}
